<?php

namespace app\common\validate\Meduser;

// 引入tp的验证器
use think\Validate;

class Meduser extends Validate
{
    // 验证规则
    protected $rule = [
        /* 
            require => 字段必填
            regex => 正则验证
            unique => 验证字段值在指定表或模型是否为唯一 
        */
        'phone' => ['require', 'regex:/^1[3456789]{1}\d{9}$/', 'unique:meduser'],
        'nickname' => ['require'],
        'password' => ['require']

    ];

    // 错误提示信息
    protected $message = [
        'phone.require' => '手机号必填',
        'phone.regex' => '手机号格式不正确',
        'phone.unique' => '手机号已注册',
        'nickname.require' => '昵称必填',
        'password.require' => '密码必填',
    ];

    // 验证场景
    protected $scene = [
        // 注册用户的验证场景
        'add' => ['phone', 'password'],
        // 用户编辑资料的场景
        'edit' => ['nickname']
    ];
}
